home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / usleep.c < prev    next >
C/C++ Source or Header  |  1994-04-04  |  2KB  |  71 lines

  1. RCS_ID_C="$Id: usleep.c,v 1.1 1994/04/04 01:30:50 jraja Exp $"
  2. /*
  3.  * usleep.c -- suspend process for the specified time
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Mon Apr  4 00:36:17 1994 jraja
  12.  * Last modified:
  13.  *
  14.  * $Log: usleep.c,v $
  15.  * Revision 1.1  1994/04/04  01:30:50  jraja
  16.  * Initial revision
  17.  *
  18.  */
  19.  
  20. #include <sys/param.h>
  21. #include <unistd.h>
  22. #include <sys/time.h>
  23. #include <sys/socket.h>
  24.  
  25. /****** net.lib/usleep *********************************************
  26.  
  27.     NAME
  28.     usleep - suspend process execution for the specified time
  29.  
  30.     SYNOPSIS
  31.     void usleep(unsigned int microseconds);
  32.  
  33.     FUNCTION
  34.         Process execution is suspended for number of microseconds
  35.         specified in 'microseconds'. The sleep will be aborted if any
  36.         of the break signals specified for the process is received
  37.         (only CTRL-C by default).
  38.  
  39.     PORTABILITY
  40.     UNIX
  41.  
  42.     INPUTS
  43.     'microseconds' - number of microseconds to sleep.
  44.  
  45.     RESULT
  46.         Does not return a value.
  47.  
  48.     NOTES
  49.         The sleep is implemented as a single select() call with all other
  50.         than time out argument as NULL.
  51.  
  52.     SEE ALSO
  53.     bsdsocket.library/select()
  54.  
  55. *****************************************************************************
  56. *
  57. */
  58.  
  59. void usleep(unsigned int usecs)
  60. {
  61.   struct timeval tv;
  62.  
  63.   tv.tv_sec = 0;
  64.   while (usecs >= 1000000) {
  65.     usecs -= 1000000;
  66.     tv.tv_sec++;
  67.   }    
  68.   tv.tv_usec = usecs;
  69.   select(0, 0, 0, 0, &tv);
  70. }
  71.